package com.wfm.service;

import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.api.VerboseProgressCallback;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.internal.DefaultShellCallback;

import org.mybatis.generator.config.xml.ConfigurationParser;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wfm
 * @create 2021-11-24-15:16
 */
//@Slf4j
public class GeneratorSqlmap {

    @Test
    public void testGenUatDeploy() throws Exception {
        GeneratorSqlmap.generator("generator-configs/generatorConfig-deploy.xml");
    }



    public static void generator(String xmlName) throws Exception {
        System.out.println("start generator...");
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        // 指定配置文件
        InputStream ins = GeneratorSqlmap.class.getClassLoader().getResourceAsStream(xmlName);

        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(ins);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(new VerboseProgressCallback());
        System.out.println("generator Done.");

    }


}
